Help for functions and procedures in fileio.e

 

      ASCII_to_EBCDIC

      CommaFormat

      ConvertAmount

      EBCDIC_to_ASCII

      FileExist

      LoadBinaryFile

      LoadPartialTextFile

      LoadTextFile

      LTrim

      Numeric

      OpenFile

      parse

      prompt_password

      ReadBinaryFile

      ReadTextFile

      Resize

      RTrim

      Trim

      Unpack

      VAL

      WriteBinaryFile

      WriteTextFile

 

 

                                      ASCII_to_EBCDIC

 

 Syntax:      include fileio.e

 

              s2 = ASCII_to_EBCDIC(s1)

 

              s1 is in ASCII format

              s2 is in EBCDIC format

 

 

 Description:

              Convert sequence s1 in ASCII format to s2, in EBCDIC format.

 

 Comments:

              EBCDIC is the format of data on IBM mainframes. Some file

              transfer programs may not convert automatically to ASCII

              format.

 

 

 Example:

              sequence ASCII_text, EBCDIC_text

 

              EBCDIC_text = ASCII_to_EBCDIC(EBCDIC_text)

 

 See also:    EBCDIC_to_ASCII

 

                                      CommaFormat

 

 Syntax:   include fileio.e

 

              s2 = CommaFormat(s1)

 

              s1 and s2 are sequences with number strings

 

 

 Description:

              Convert a text number without commas to a text string

              with commas after each three decimal places.

 

 

 Example:

              sequence raw_number, converted_num

          raw_number = 1234.56

 

          converted_num = CommaFormat(raw_number)

 

             -- converted_num  is 1,234.56

 

 

 See also:    ConvertAmount

 

 

                                      ConvertAmount

 

 Syntax:   include fileio.e

 

              s2 = ConvertAmount(s1, i)

 

 Description:

              Convert a text number with a trailing sign digit to one

              with or without a negative sign at the beginning

 

              i is an integer specifying the number of decimals desired.

 

 Comments:

              s1 is a number in text format with a sign at the end.

 

              for example,

                 }ABCDEFGHI converts to

                 0123456789

 

                    and

 

                 {JKLMNOPQR converts to

                 0123456789 with a negative sign

 

 Example:

             sequence converted_num, num_with_trailing_sign

 

             converted_num = ConvertAmount(num_with_trailing_sign, 2)

 

 

                                      EBCDIC_to_ASCII

 

 Syntax:   include fileio.e

 

              s2 = EBCDIC_to_ASCII(s1)

 

              s1 is in EBCDIC format

              s2 is in ASCII format

 

 

 Description:

              Convert sequence s1 in EBCDIC format to s1, in ASCII format.

 

 Comments:

              EBCDIC is the format of data on IBM mainframes. Some file

              transfer programs may not convert automatically to ASCII

              format.

 

 

 Example:

              sequence ASCII_text, EBCDIC_text

 

              ASCII_text = EBCDIC_to_ASCII(EBCDIC_text)

 

 See also:    ASCII_to_EBCDIC

 

                                         FileExist

 

 Syntax:   include fileio.e

 

              i = FileExist(OUT_FILENAME)

              i is an integer, 1 or 0 which indicates whether the file path is

              found.  If the file exists, a message box appears on the screen,

              requesting whether it is okay to overwrite the file.

 

 Description:

              returns 1 if the specified file path is found and it is not okay to

              overwrite the file, 0 if it is not found, or if it is okay to overwrite

              the file.

 

 

 Example:

              sequence OUT_FILENAME

              FILENAME = "C:\\EUPHORIA\\DEMO\\DEMO.EX

              if FileExist(OUT_FILENAME) then

                Write_New_Output_File(OUT_FILENAME)

              else

                abort(1)

              end if

 

 

                                       LoadBinaryFile

 

 Syntax:   include fileio.e

 

              s2 = LoadBinaryFile(s1, i)

              s1 and s2 are sequences, s1 is the name of the file

              i is an integer specifying the length of each line in a file

 

 Description:

              Loads an entire Binary file into a sequence, with a length

              specified.

 

 Example:

              sequence line_array, filename

              line_array = LoadBinaryFile(filename, 80)

 

 See also:    LoadTextFile, ReadBinaryFile

 

                                      LoadPartialTextFile

 Syntax:   include fileio.e

 

              s = LoadPartialTextFile(a)

 

 Description: Loads part of a text file into sequence s

              parm passed consists of {Filename and starting record} or,

                                      {Filename, starting record, ending record}

 

 Comments: Returns an empty sequence {} if the file is empty or

                 if it does not exist, or there are no records in the range

 

 Example 1:

              sequence filename, line_array

              filename = "C:\\euphoria\\demo.ex"

 

              line_array = LoadPartialTextFile({filename, 5})

              -- line_array contains the first 5 records

 

 Example 2:

              sequence filename, line_array

              filename = "C:\\euphoria\\demo.ex"

 

              line_array = LoadPartialTextFile({filename, 5, 7})

              -- line_array contains the records 5, 6, 7

 

 See also:    LoadTextFile

 

 

                                        LoadTextfile

 

 Syntax:   include fileio.e

 

              s = LoadTextFile(fn)

 

 Description: Loads an entire text file into sequence s

 

 

 Comments: Returns an empty sequence {} if the file is empty or

                 if it does not exist.

 

 Example:

              sequence filename, line_array

              filename = "C:\\euphoria\\demo.ex"

 

              line_array = LoadTextFile(filename)

 

 See also:    LoadBinaryFile

 

 

                                           LTrim

 

 Syntax:   include fileio.e

 

              s2 = LTrim(s1)

 

              s1 and s2 are strings

 

 

 Description: Trims leading spaces from a sequence

 

 Example:

              sequence s1, s2

              s1 = "   ABC"

 

              s2 = LTrim(s1)

              -- s2 is "ABC"

 

 

 See also:    RTrim, Trim

 

 

                                         Numeric

 

 Syntax:   include fileio.e

 

              i1 = Numeric(s1)

 

              i1 is an integer 0 or 1

              s1 is a string that will be check for all numeric characters

 

 

 Description:   Checks a sequence for all numeric characters, including '+', '-', and '.'

                   If more than one decimal point is found, the sequence is not numeric.

 

 

 Example 1:

              sequence number_string

 

              if Numeric("-123.45") then

                puts(1, "this is numeric\n")

              else

                puts(1, "this is not numeric\n")

              end if

 

              -- result: "this is numeric"

 

 Example 2:

              sequence number_string

 

              if Numeric("-12.3.45") then

                puts(1, "this is numeric\n")

              else

                puts(1, "this is not numeric\n")

              end if

 

              -- result: "this is not numeric"

 

 

                                        OpenFile

 

 Syntax:   include fileio.e

 

              OpenFile(s1, s2)

 

 Description: Opens a file when given the name and type of the file

              returns the number of the file assigned

 

              s1 is any valid path and filename

              s2 is any of the valid defined open methods for

              a file.  For example, "r", "rb", "w", "wb"

 

 Example:

              integer fn

              fn = OpenFile("C:\\euphoria\\example.ex", "r")

 

 

                                           parse

 

 Syntax:   include fileio.e

 

              s2 = parse({s1})

 

              s1 and s2 are sequences

 

 

 Description: Separates a string into substrings delimited by spaces or optional

                  delimiter entered.

 

 

 Example 1:

              sequence all_names, name

 

              all_names = "Joe John Adam Hank"

              name = parse({all_names})

              --name[1] is "Joe"

              --name[2] is "John"

              --name[3] is "Adam"

              --name[4] is "Hank"

 

 Example 2:

              sequence all_names, name

 

              all_names = "Joe,,John,Adam,Hank"

              name = parse({all_names, ','})

              --name[1] is "Joe"

              --name[2] is ""

              --name[2] is "John"

              --name[3] is "Adam"

              --name[4] is "Hank"

 

 

                                    prompt_password

 

 Syntax:   include fileio.e

 

              s2 = prompt_password(s1)

 

              s1 and s2 are strings

 

 

 Description: Prints '*' instead of keystrokes for password entry

                  Press Enter to return password, or ESC to exit.

 

 Example:

              constant MAX_TRIES = 3

              sequence password

              integer tries

 

              tries = 0

              do while not equal(password, "SECRET") and tries < MAX_TRIES do

                position(1,1)  password = prompt_password("Enter password : ")

                tries += 1

              end while

 

              if not equal(password, "SECRET") then

                puts(1, "password not matched\n")

                abort(1)

              end if

 

 

                                       ReadBinaryFile

 

 Syntax:   include fileio.e

 

              s = ReadBinaryFile(fn)

 

 Description: Reads a line of a binary file with file number fn.

 

 Comments:  File must be opened as binary

 

 

 Example:

              sequence filename, line_array

              filename = "C:\\euphoria\\demo.ex"

              fn = OpenFile(filename, 80)

 

              line = ReadBinaryFile(fn)

 

              if line[1] = 0 then           -- EOF

                return

              end if

 

 See also:    ReadTextFile, LoadBinaryFile

 

 

                                        ReadTextFile

 

 Syntax:   include fileio.e

 

              s = ReadTextFile(fn)

 

 Description: Reads a line of a text file, and returns the status of the

              read and the line of text, if successful.

              s  is a  sequence

              fn is an integer of the file number of the open file

 

 Example:

              sequence line, text

              integer fn

 

              line = ReadTextfile(fn)

              if line[1] = 0           -- EOF

                return

              end if

              text = line[2]

 

 See also:    ReadBinaryFile, LoadTextFile

 

 

                                           Resize

 

 Syntax:   include fileio.e

 

              s2 = Resize(s1, i)

 

              s1 and s2 are sequences, i is an integer

 

 Description: If a line is longer than the specified length, it is truncated.

              If a line is shorter, it is padded with blanks to the

              specified length.

 

 Example 1:

              sequence line

 

              line = "1234567890ABCDEF"

              line = Resize(line, 10)

              -- line is "1234567890"

 

 Example 2:

              sequence line

              line = {"123",

                      "1234567890ABC",

                       "12345"

                     }

 

              line = Resize(line, 15)

              -- line is {

              "123            ",

              "1234567890ABC  ",

              "12345          "

              }

 

 

                                          RTrim

 

 Syntax:   include fileio.e

 

              s2 = RTrim(s1)

 

              s1 and s2 are strings

 

 

 Description: Trims trailing spaces from a sequence

 

 Example:

              sequence s1, s2

              s1 = "ABC   "

 

              s2 = RTrim(s1)

              -- s2 is "ABC"

 

 

 See also:    LTrim, Trim

 

 

                                          Trim

 

 Syntax:   include fileio.e

 

              s2 = Trim(s1)

 

              s1 and s2 are strings

 

 

 Description:  Trims leading spaces and trailing spaces from a sequence

 

 Example:

              sequence s1, s2

              s1 = "   ABC   "

 

              s2 = LTrim(s1)

              -- s2 is "ABC"

 

 

 See also:    LTrim, RTrim

 

 

                                          Unpack

 

 Syntax:   include fileio.e

 

              Unpack(s1, i)

 

              s1 is the sequence to be unpacked,

              i is the number of decimals in the result

 

 Description:  If a number is compressed into half-bytes, Unpack converts

                   by using the hexadecimal value of each half-byte

 

 

 

 Example:

              sequence unpacked_num, packed_num

              integer numdec

 

              unpacked_num = Unpack(packed_num, 2)

 

 

                                            VAL

 

 Syntax:   include fileio.e

 

              a = VAL(s)

 

              a is an atom or an integer, s is a numeric sequence

 

 

 Description:  Convert a numeric sequence to an atom or an integer representing

                   the value of the numeric expression.

 

 

 

 Example:

              sequence numeric_expression, ABC

              atom amount

 

              ABC = AA123.45XYZ"

              numeric_expression = ABC[2..7]

              amount = VAL(numeric_expression)

              --amount is 123.45

 

 

                                       WriteBinaryFile

 

 Syntax:   include fileio.e

 

              WriteBinaryFile(s1, s2)

              s1 is the name of the file, s2 is the sequence to be saved

 

 Description: Writes a binary file with name s1, of the sequence s2

 

 Example:

              sequence line_array

              line_array = {"abcdefghi"}

              WriteBinaryFile(filename, line_array)

 

 See also:    WriteTextFile

 

                                        WriteTextFile

 

 Syntax:   include fileio.e

 

              WriteTextFile(s1, s2)

              s1 is the name of the file, s2 is the sequence to be saved

 

 Description: Writes a text file with name s1, of the sequence s2

 

 Comments: Adds a line feed after each line

 

 Example:

              sequence line_array

              line_array = {"abcdefghi"}

              WriteTextFile(filename, line_array)

 

 See also:    WriteBinaryFile